/* s^2 - HTTP methods
   Copyright (C) 2018 Ariadne Devos

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>. */

#ifndef _sHT_WEB_METHOD_H
#define _sHT_WEB_METHOD_H

#include <stddef.h>
#include <stdint.h>
#include <sys/uio.h>

enum s2_http_method
{
	S2_HTTP_METHOD_UNKNOWN = 0,
	S2_HTTP_METHOD_OPTIONS,
	S2_HTTP_METHOD_GET,
	S2_HTTP_METHOD_HEAD,
	S2_HTTP_METHOD_POST,
	S2_HTTP_METHOD_PUT,
	S2_HTTP_METHOD_DELETE,
	S2_HTTP_METHOD_TRACE,
	S2_HTTP_METHOD_CONNECT,

	S2_WEBDAV_METHOD_PROPFIND,
	S2_WEBDAV_METHOD_PROPPATCH,
	S2_WEBDAV_METHOD_MKCOL,
	S2_WEBDAV_METHOD_COPY,
	S2_WEBDAV_METHOD_MOVE,
	S2_WEBDAV_METHOD_LOCK,
	S2_WEBDAV_METHOD_UNLOCK,
};
#define S2_HTTP_METHOD_MAX S2_HTTP_METHOD_UNLOCK

#define S2_HTTP_METHOD_MAX_LENGTH 9

/** Map a method name to its @var{s2_http_method} identifier

  @var{string}: the method name
  @var{length}: the length of the method name -- not its buffer's!

  All first @var{S2_HTTP_METHOD_MAX_LENGTH} characters of @var{string}
  may be read.

  If no such method is recognised, return @var{S2_HTTP_METHOD_UNKNOWN}.
  The return value may speculatively be incorrect, but it is always a
  @var{s2_http_method}. */
size_t
s2_http_method_lookup(const uint8_t string[], size_t length);

#endif
